Imports System
Imports NUnit.Framework
Imports ValidationFramework


Namespace PropertyValidationManagerExamples
    Public Class GuardExample
#Region "Example"
        Public Class Person

            Private _age As Integer
            Private propertyValidationManager As PropertyValidationManager

            Public Sub New()
                propertyValidationManager = New PropertyValidationManager(Me)
            End Sub


            ' Properties
            <RequiredIntRule()> _
            Public Property Age() As Integer
                Get
                    Return _age
                End Get
                Set(ByVal value As Integer)
                    If value <> _age Then
                        propertyValidationManager.ThrowException(value, "Age", Nothing)
                        _age = value
                    End If
                End Set
            End Property

        End Class


        <TestFixture()> _
        Public Class ExampleUsage
            <Test(), ExpectedException(GetType(ArgumentException))> _
            Public Sub RunInvalid()
                Dim person As New Person
                ' Works because 10 is valid
                person.Age = 10
                ' Fails because 0 is invalid
                person.Age = 0
            End Sub

            <Test()> _
            Public Sub RunIsValid()
                Dim person As New Person
                ' Works because 10 is valid
                person.Age = 10
            End Sub

        End Class

#End Region
    End Class
End Namespace